package demo;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Singleton;

@Singleton
public class DemoDataStore {

	private Map<Long, Project> projectMap = new HashMap<Long, Project>();
	private static int lastProjectId = 3;

	public List<Project> getProjectList() {
		return new ArrayList<Project>(projectMap.values());
	}

	public Project save(Project project)
	{
		if (project.getId() == null || project.getId() == 0)
		{
			lastProjectId++;
			project.setId(Long.valueOf(lastProjectId));
		}
		projectMap.put(project.getId(), project);
		return project;
	}
	
	public void init() {
		projectMap.put(1l, new Project(1l, "PRJ1", "Project 1", "Long name of Project 1"));
		projectMap.put(2l, new Project(2l, "PRJ2", "Project 2", "Long name of Project 2"));
		projectMap.put(3l, new Project(3l, "PRJ3", "Project 3", "Long name of Project 3"));
		projectMap.get(1l).addMilestone(new Milestone(1l, "M1", "Milestone 1", new GregorianCalendar(2011, Calendar.JUNE, 27).getTime()));
		projectMap.get(1l).addMilestone(new Milestone(2l, "M2", "Milestone 2", new GregorianCalendar(2011, Calendar.JULY, 01).getTime()));
		projectMap.get(2l).addMilestone(new Milestone(3l, "M1", "Milestone 1", new GregorianCalendar(2011, Calendar.JULY, 15).getTime()));
		projectMap.get(3l).addMilestone(new Milestone(4l, "M1", "Milestone 1", new GregorianCalendar(2011, Calendar.JULY, 20).getTime()));
	}
	
}
